// MainActivity.java
public class MainActivity extends Activity {
        private GridView appGrid;

            @Override
                protected void onCreate(Bundle savedInstanceState) {
                            super.onCreate(savedInstanceState);
                                    
                                            // 基本布局设置
                                                    FrameLayout layout = new FrameLayout(this);
                                                            appGrid = new GridView(this);
                                                                    layout.addView(appGrid);
                                                                            setContentView(layout);

                                                                                    // 设置透明背景
                                                                                            getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                                                                                                    
                                                                                                            // 加载应用列表
                                                                                                                    loadApps();
                }

                    private void loadApps() {
                                // 获取所有应用
                                        PackageManager pm = getPackageManager();
                                                Intent intent = new Intent(Intent.ACTION_MAIN, null);
                                                        intent.addCategory(Intent.CATEGORY_LAUNCHER);
                                                                
                                                                        List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0);
                                                                                Collections.sort(apps, new ResolveInfo.DisplayNameComparator(pm));
                                                                                        
                                                                                                // 创建适配器
                                                                                                        AppAdapter adapter = new AppAdapter(this, apps);
                                                                                                                appGrid.setAdapter(adapter);
                                                                                                                        
                                                                                                                                // 设置点击事件
                                                                                                                                        appGrid.setOnItemClickListener((parent, view, position, id) -> {
                                                                                                                                                        ResolveInfo info = apps.get(position);
                                                                                                                                                                    startActivity(pm.getLaunchIntentForPackage(info.activityInfo.packageName));
                                                                                                                                        });
                                                                                                                                                
                                                                                                                                                        // 设置网格参数
                                                                                                                                                                appGrid.setNumColumns(4);
                                                                                                                                                                        appGrid.setVerticalSpacing(20);
                                                                                                                                                                                appGrid.setHorizontalSpacing(20);
                    }

                        // 应用适配器
                            private class AppAdapter extends BaseAdapter {
                                        private final LayoutInflater inflater;
                                                private final List<ResolveInfo> apps;
                                                        private final PackageManager pm;

                                                                AppAdapter(Context context, List<ResolveInfo> apps) {
                                                                                this.apps = apps;
                                                                                            pm = context.getPackageManager();
                                                                                                        inflater = LayoutInflater.from(context);
                                                                }

                                                                        @Override
                                                                                public int getCount() { return apps.size(); }

                                                                                        @Override
                                                                                                public Object getItem(int position) { return apps.get(position); }

                                                                                                        @Override
                                                                                                                public long getItemId(int position) { return position; }

                                                                                                                        @Override
                                                                                                                                public View getView(int pos, View convertView, ViewGroup parent) {
                                                                                                                                                if (convertView == null) {
                                                                                                                                                                    convertView = inflater.inflate(R.layout.app_item, null);
                                                                                                                                                }
                                                                                                                                                            
                                                                                                                                                                        ResolveInfo info = apps.get(pos);
                                                                                                                                                                                    ImageView icon = convertView.findViewById(R.id.app_icon);
                                                                                                                                                                                                TextView name = convertView.findViewById(R.id.app_name);
                                                                                                                                                                                                            
                                                                                                                                                                                                                        icon.setImageDrawable(info.loadIcon(pm));
                                                                                                                                                                                                                                    name.setText(info.loadLabel(pm));
                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                            return convertView;
                                                                                                                                }
                            }
}
                                                                                                                                                }
                                                                                                                                }
                                                                }
                            }
                                                                                                                                        })
                    }
                }
}